<template>
  <van-address-edit
      show-delete
      show-set-default
      :show-search-result="false"
      :show-area="false"
      :address-info="AddressInfo"
      :search-result="searchResult"
      :area-columns-placeholder="['请选择', '请选择', '请选择']"
      @save="onSave"
      @delete="onDelete"
      @change-detail="onChangeDetail"
  />
</template>

<script>
import {AddressEdit} from "vant";
import {Toast} from "vant";
import Vue from "vue";

Vue.use(AddressEdit);
import {mapState, mapMutations} from "vuex";

export default {
  data() {
    return {
      // areaList,
      searchResult: [],
      AddressInfo: {
        id: 0,
        name: 'liy',
        tel: '12345678901',
        addressDetail: "132313213"
      },
      addressInfo2: {},
      list: [],
    };
  },
  props: {
    name: String
  },
  computed: {
    ...mapState({
      addressInfo: {
        get: (state) => state.address.addressInfo
      },

    }),
  },
  async created() {

  },
  mounted() {
    let index = this.$store.state.selectedIndex || 0;
    window.app = this;
    this.list = this.$store.state.address.addressInfo;
    this.addressInfo2 = this.list[index];
    // this.AddressInfo.name = this.addressInfo.name;
    // this.AddressInfo.tel = this.addressInfo.tel;
    // this.AddressInfo.addressDetail = this.addressInfo.address;
    this.AddressInfo.name = this.addressInfo2.name;
    this.AddressInfo.tel = this.addressInfo2.tel;
    this.AddressInfo.addressDetail = this.addressInfo2.address;
    this.AddressInfo.isDefault = this.addressInfo2.isDefault;

    console.log(this.list);
  },
  getters: {
    name: state => {
      return state.address.addressInfo.name;
    },

  },

  methods: {
    onSave(content) {
      console.log(content)
      this.addressInfo2.name = content.name;
      this.addressInfo2.tel = content.tel;
      this.addressInfo2.address = content.addressDetail;
      this.addressInfo2.isDefault = content.isDefault;

      Toast("save");
      this.$router.push({
        path: "/home/AddressManage",
      });
    },
    onDelete() {
      Toast("delete");
      this.$store.state.address.addressInfo.splice(this.$store.state.selectedIndex,1)
      this.$router.push({
        path: "/home/AddressManage",
      });
    },
    onChangeDetail(val) {
      if (val) {
        this.searchResult = [
          {
            name: "黄龙万科中心",
            address: "杭州市西湖区",
          },
        ];
      } else {
        this.searchResult = [];
      }
    },
  },
};
</script>

<style lang="scss" scoped>
.van-address-edit {
  padding: 12px;
  padding-top: 59px;
  height: 700px;
}

.van-cell {
  position: relative;
  display: -webkit-box;
  display: -webkit-flex;
  display: flex;
  box-sizing: border-box;
  width: 100%;
  padding: 10px 16px;
  overflow: hidden;
  color: #323233;
  font-size: 14px;
  line-height: 24px;
  background-color: #fff;
  height: 56px !important;
}

.van-cell {
  position: relative;
  display: -webkit-box;
  display: -webkit-flex;
  display: flex;
  box-sizing: border-box;
  width: 100%;
  padding: 18px 16px;
  overflow: hidden;
  color: #323233;
  font-size: 14px;
  line-height: 24px;
  background-color: #fff;
}

.van-address-edit__fields {
  overflow: hidden;
  border-radius: 8px;
  height: 300px;
}
</style>
